Skip to content

Conversation

@astappiev
Copy link

@astappiev astappiev commented Feb 13, 2025

Inspired by #2611 and talks in #1555 created a script to update peer-port of qBittorrent.

Upd: added option to authenticate.

@AndaPlays
Copy link

I'm currently working on something similar, but I guess this would be a better solution. 👍

@astappiev
Copy link
Author

The only downside of these scripts is that they don't cover a scenario when a client is started after gluetun.

@AndaPlays
Copy link

@astappiev Looks good to me. The only thing I would appreciate is if we could add an option for Nmap to check whether the port is actually open. I'm on a couple of private trackers, and if my TCP port is filtered, I could get heat—or in the worst case—have my account banned.

I tried integrating it into my script and controlling the VPN via the control server, but Gluetun doesn't have an API for WireGuard yet.

@astappiev
Copy link
Author

I think it should be implemented as another script (as it is not client dependent), or even in the gluetun core.

@qdm12

This comment was marked as off-topic.

@qdm12

This comment was marked as off-topic.

@qdm12 qdm12 changed the title Add script to update qBittorrent peer port feat(extras/scripts): update qBittorrent peer port with optional authentication Nov 13, 2025
echo " (Omit if not required)"
echo " -p, --pass PASS Specify the qBittorrent password."
echo " (Omit if not required)"
echo " -P, --port PORT Specify the qBittorrent peer-port."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should accept a comma separated list of ports from Gluetun's {{PORTS}} to simplify usage of this script.
And then it should use $(echo {{PORTS}} | cut -d, -f1) to take only the first port just in case, since qbitorrent supports only one port.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I got it right, does it mean we should use it like this bittorrent-port-update.sh --port {{PORTS}}?

E.g. via VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c "/scripts/qbittorrent-port-update.sh --port {{PORTS}} --webui-port 9081"

If so, it's already supported, this is exactly how I used it since beggining.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but {{PORTS}} can have multiple ports so for convenience and a shorter command, let's cut and use the first port within the script. The flag should be renamed to --ports and indicate that despite the name it only picks the first port

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the other way around, let's keep it named as --port to indicate that only one of them is used.

The logic to split and keep the first was already there
https://github.com/astappiev/gluetun/blob/839e318c9c30676c8ecd9f042c524e87a1634f32/extras/scripts/qbittorrent-port-update.sh#L60

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually....
Added support for {{PORT}} variable in fcdba0a which takes the first of the ports. No reason to have it supported in scripts!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the example to use --port {{PORT}}, but left PORT=$(echo "$2" | cut -d',' -f1) in to keep it more foolproof

@AndaPlays

This comment was marked as off-topic.

@qdm12
Copy link
Owner

qdm12 commented Nov 14, 2025

@AndaPlays for this nmap command to succeed, I suppose you do need a program listening on the forwarded port right? What I'm thinking is to, when setting up port forwarding:

  1. start an ephemeral tcp server on the forwarded port / if the port is used already then don't that's fine too (udp is more complicated and not widely used by users so we'll skip that)
  2. check public-ip:port with a tcp dial (same as the nmap command)
  3. Report to debug logs it is open and finish the port forwarding setup process (I'm a maniac of logging problems only and avoid logging if things work correctly)

I'm going to mark our comments as off topic, would you please open an issue for this? Thanks!!

@monstermuffin
Copy link

Hey guys, I know it's not a native solution but this use case is exactly why I made qSticky. Been working very well and it doesn't matter what order things come up as it's a middleman between the two applications.

fi

# update peer host via API, 0 is a dummy port, required due to https://github.com/qdm12/gluetun-wiki/pull/147
wget ${WGET_OPTS} -qO- --post-data="json={\"random_port\":false,\"upnp\":false,\"listen_port\":0}" "$PREF_URL/v2/app/setPreferences"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per #2997 (comment)
let's add

Suggested change
wget ${WGET_OPTS} -qO- --post-data="json={\"random_port\":false,\"upnp\":false,\"listen_port\":0}" "$PREF_URL/v2/app/setPreferences"
wget ${WGET_OPTS} -qO- --post-data="json={\"random_port\":false,\"upnp\":false,\"listen_port\":0,\"current_network_interface\":\"\",\"current_interface_address\":\"\"}" "$PREF_URL/v2/app/setPreferences"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added that, but maybe let's use lo as a temporal interface; it feels safer.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! Updated the wiki with that suggestion.

fi

# second call to set the actual port
wget ${WGET_OPTS} -qO- --post-data="json={\"listen_port\":$PORT}" "$PREF_URL/v2/app/setPreferences"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wget ${WGET_OPTS} -qO- --post-data="json={\"listen_port\":$PORT}" "$PREF_URL/v2/app/setPreferences"
wget ${WGET_OPTS} -qO- --post-data="json={\"listen_port\":$PORT,\"current_network_interface\":\"$VPN_INTERFACE\",\"current_interface_address\":\"0.0.0.0\"}" "$PREF_URL/v2/app/setPreferences"

and I'll add a {{VPN_INTERFACE}} to the template variable available to the command.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, but I'm concerned by the 0.0.0.0 as the default address.
It means we restrict to never use IPv6 (I don't know if there are any IPv6 VPNs)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are (airvpn, mullvad) AFAIK; I copied this from a comment of someone; any idea if we can make it for all ipv4 and ipv6? What's the default? Maybe not touching that one would be a better idea.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New template variable {{VPN_INTERFACE}} is available, so we can use it for the current network interface json field.

# How to use:
# 1. (Optional) Disable authentication for localhost clients in qBittorrent WebUI settings ("Bypass authentication for clients on localhost" or `bypass_local_auth` in json).
# 2. Set the environment variable:
# VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c "/scripts/qbittorrent-port-update.sh --port {{PORT}} --webui-port 9081"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c "/scripts/qbittorrent-port-update.sh --port {{PORT}} --webui-port 9081"
# VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c "/scripts/qbittorrent-port-update.sh --port {{PORT}} --iface {{VPN_INTERFACE}} --webui-port 9081"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants